#include <mysql/mysql.h>
#include <string.h>
#include <stdio.h>

int insertNewfile(int parentID, char *filename, int ownerID, char *md5str, int filesize, char type)
{
	MYSQL *conn;
	char *server = "localhost";
	char *user = "chen";
	char *password = "123";
	char *database = "37chen";//要访问的数据库名称
    char buf[200]="insert into file (parent_id,filename,owner_id,md5,filesize,type) values ";
    char query[400] = {0};

    //拼接
    sprintf(query, "%s(%d,'%s',%d,'%s',%d,'%c')", buf,parentID,filename,ownerID,md5str,filesize,type);
    puts(query);

	int queryResult;

	conn = mysql_init(NULL);

	if(!mysql_real_connect(conn, server, user, password, database, 0, NULL, 0))
	{
		printf("Error connecting to database: %s\n", mysql_error(conn));
	}
    else
    {
		printf("Connected...\n");
	}

	queryResult = mysql_query(conn, query);
	if(queryResult)
	{
		printf("Error making query:%s\n", mysql_error(conn));
	}
    else
    {
		printf("insert success\n");
	}
	mysql_close(conn);

	return 0;
}